package com.some;

import java.util.*;

public class TenXun {

    public int getLastNum(int[] nums) {
        List<Integer> numList = new ArrayList<>();
        for (int num : nums) {
            numList.add(num);
        }
        List<Integer> primeList = primeNumber(numList.size());
        while (numList.size() > 1) {
            for (int i = numList.size() - 1; i >= 0; i--) {
                if (!primeList.contains(i + 1)) {
                    numList.remove(i);
                }
            }
        }
        return numList.get(0);
    }

    public List<Integer> primeNumber(int length) {
        List<Integer> list = new ArrayList<>();
        for (int i = 2; i <= length; i++) {
            int j = 2;
            while (i % j != 0) {
                j++;
            }
            if (j == i) {
                list.add(i);
            }
        }
        return list;
    }

    public static void main(String[] args) {
/*        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        ArrayList<Integer> list = new ArrayList<>();
        for (char c : str.toCharArray()) {
            if (c <= '9' && c >= '0') {
                list.add(c - '0');
            }
        }
        TenXun tenXun = new TenXun();
        System.out.println(tenXun.getLastNum(list));*/

    }
}
